<template>
  <div class="search">
    <f-drawer ref="bmpDrawer" :title="drawerTitle" width="90%" @submit="handleSubmit" @visibleChange="visibleChange">
      <a-tabs @tabClick="tabClick" :defaultActiveKey="current" v-model="current">
        <a-tab-pane tab="包商信息" key="form1">
          <bmp-form ref="form1" v-if="drawerVisible" :detailsParams="detailsParams"></bmp-form>
        </a-tab-pane>
      </a-tabs>
    </f-drawer>
  </div>
</template>
<script>
  import api from './js/apiProjectSupplier'
  import bmpForm from './bmp_form.vue'

  export default {
    name: 'bmpDrawer',
    props: {},
    data() {
      return {
        refs: this.$refs,
        drawerVisible: false,
        isEdit: false,
        title: '',
        current: 'form1',
        formData: {},
        forms: [
          'form1'
        ],
        detailsParams: {}
      }
    },
    methods: {
      showDrawer(recordData) {
        this.getFormData(recordData)
      },
      handleSubmit(callback) {
        this.refs[this.current].handleSubmit(callback)
      },
      visibleChange(drawerVisible) {
        this.drawerVisible = drawerVisible
      },
      tabClick(name) {
        this.current = name
        this.$nextTick(() => {
          this.refs[this.current].setData(this.formData)
        })
      },
      getFormData(recordData) {
        this.detailsParams.projectId = recordData.projectId
        this.detailsParams.packageNo = recordData.packageNo
        this.detailsParams.majorCode = recordData.majorCode
        this.http.get(this, {
          url: api.bps.getBusProjectSupplier,
          data: this.detailsParams,
          success(me, data) {
            me.formData = data
            me.isEdit = false
            if (me.formData.projectSupplierId) {
              me.isEdit = true
            } else {
              me.formData = {}
            }
            me.refs['bmpDrawer'].show()
            me.tabClick('form1')
          }
        })
      }
    },
    computed: {
      drawerTitle: function() {
        return this.title
      }
    },
    created() {
    },
    components: { bmpForm }
  }
</script>

<style scoped lang="less" rel="stylesheet/less">

</style>
